package com.googlecode.struts2scope;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class ScopeInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = 118253350896152579L;

	private ContextExecutionFlow[] contextExecutionFlows = new ContextExecutionFlow[] {new GenericContextExecutionFlow()}; 

	public String intercept(ActionInvocation invocation) throws Exception {
		for (ContextExecutionFlow contextExecutionFlow : contextExecutionFlows) {
			contextExecutionFlow.init(invocation);
			
			contextExecutionFlow.before();
		}
		String result = invocation.invoke();
		for (ContextExecutionFlow contextExecutionFlow : contextExecutionFlows) {
			contextExecutionFlow.after();
		}
		return result;
	}

}
